package com.yf.zzmusic.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yf.zzmusic.common.Constants;
import com.yf.zzmusic.common.Result;
import com.yf.zzmusic.pojo.dto.music.MusicUpdateDTO;
import com.yf.zzmusic.pojo.dto.slide.SlideUpdateDTO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

import com.yf.zzmusic.service.ISlideService;
import com.yf.zzmusic.pojo.entity.Slide;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 轮播图 前端控制器
 * </p>
 *
 * @author
 * @since 2024-02-28
 */
@RestController
@RequestMapping("/slide")
public class SlideController {
    @Resource
    private ISlideService slideService;

    @PostMapping("/insert")
    public Result save(@RequestBody Slide slide) {
        boolean result=slideService.save(slide);
        if (result){
            return Result.success("新增成功");
        }else{
            return Result.error("新增失败");
        }
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        boolean result = slideService.removeById(id);
        if (result){
            return Result.success("删除成功",null);
        }else{
            return Result.error(Constants.NO_CONTENT,"删除失败");
        }
    }

    //修改
    @PostMapping("/update")
    public Result update(@Validated @RequestBody SlideUpdateDTO slideUpdateDTO) {
        boolean result=slideService.updateSlide(slideUpdateDTO);
        if (result){
            return Result.success("修改成功",null);
        }else{
            return Result.error("修改失败");
        }
    }

    @GetMapping
    public Result findAll() {
        List<Slide> slides=slideService.list();
        if (slides.size()>0){
            return Result.success("查询成功",slides);
        }else {
            return Result.error(Constants.NO_CONTENT,"查询失败");
        }
    }

    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        Slide slide= slideService.getById(id);
        if (slide!=null){
            return Result.success("查询成功",slide);
        }else{
            return Result.error(Constants.NO_CONTENT,"查询失败");
        }
    }

}

